<?php
namespace Admin\Model;

use Think\Model;

class RoleModel extends Model{
    
//     protected $connection = 'DB_CONFIG2';
//     protected $tablePrefix = 'ty_';
    /**
     * 获取所有角色
     * @param unknown $allAdmin
     */
    public function getAccess($allAdmin){
        foreach($allAdmin as$key=> $admin){
            //TODO:暂留注释代码
            $where['ad.id'] = $admin['id'];         
            $result = $this->alias("as r")->field('ad.id as admin_id,ad.admin_name,r.name as level,ad.status,ad.create_time,ad.update_time')->//,a.access_name
            //join(C('DB_PREFIX').'access as a ON r.id = a.role_id')->
            join(C('DB_PREFIX').'server_admin as ad ON r.id = ad.role_id')->
            where($where)->find();
            
            $list[$key] = $result;
        }
        return $list;
    }
    
    /**
     * 查找角色信息
     * @param unknown $where
     */
    public function findRole($where){
        if(empty($where)){
            return false;
        }
        $result = $this->where($where)->find();
        if($result){
            return $result;
        }else{
            return false;
        }
    }
    
    /**
     * 更新角色信息
     * @param unknown $where
     */
    public function updateRole($where,$data){
        if(empty($where)){
            return false;
        }
        $result = $this->where($where)->save($data);
        if($result){
            return true;
        }else{
            return false;
        }
    }

}

?>